#include "ModelPostureBone.h"
#include <tinyxml.h>
#include "Tools.h"

ModelPostureBone::ModelPostureBone() {}
ModelPostureBone::ModelPostureBone(const ModelPostureBone&) {}
ModelPostureBone::~ModelPostureBone() {}

void ModelPostureBone::Initialize(TiXmlElement* pModelPostureBoneElement)
{
	mBoneName = std::string(pModelPostureBoneElement->Attribute("boneName"));
	std::string strRotation = std::string(pModelPostureBoneElement->Attribute("rotation"));
	mRotation = StringToQuaternion(strRotation);
}

std::string ModelPostureBone::GetBoneName()
{
	return mBoneName;
}

XMFLOAT4X4 ModelPostureBone::GetTransform()
{
	XMFLOAT4X4 result;
	XMStoreFloat4x4(&result, XMMatrixRotationQuaternion(XMLoadFloat4(&mRotation)));
	return result;
}

XMFLOAT4 ModelPostureBone::GetQuaternion()
{
	return mRotation;
}

XMFLOAT4X4 GetModelPostureBoneLerp(ModelPostureBone* pModelPostureBone1, ModelPostureBone* pModelPostureBone2, float pTime)
{
	XMVECTOR quaternionResult = XMQuaternionSlerp(XMLoadFloat4(&pModelPostureBone1->GetQuaternion()),XMLoadFloat4(&pModelPostureBone2->GetQuaternion()),pTime);
	XMFLOAT4X4 result;
	XMStoreFloat4x4(&result, XMMatrixRotationQuaternion(quaternionResult));
	return result;
}